import React from 'react'
import StatCard from '@/components/sun2/StatCard'
import { AnalysisResult } from '@/types/sun'

interface SummaryStatsProps {
  data: AnalysisResult
  isSunRoute: () => boolean
}

const SummaryStats: React.FC<SummaryStatsProps> = ({ data, isSunRoute }) => (
  <div className="grid grid-cols-2 gap-2 sm:grid-cols-3 md:grid-cols-4">
    {/* 战斗时间 */}
    {data?.sumary.time_range && (
      <StatCard
        color="sky"
        title1="战斗时间"
        title2={
          data?.sumary.time_range_start + '~' + data?.sumary.time_range_end
        }
        value={data?.sumary.time_range}
        tooltip="本次战斗的起止时间与总时长。"
        className="col-span-2 sm:col-span-1"
      />
    )}

    {/* 总人数 */}
    {isSunRoute() && data?.sumary.total && (
      <StatCard
        color="blue"
        title1="双方参战总人数"
        value={data?.sumary.total.toLocaleString()}
        tooltip="本场战斗中遭遇过的所有玩家总数。"
      />
    )}

    {/* 敌军人数 */}
    {data?.sumary.enemy_count !== null && data?.sumary.enemy_count !== 0 && (
      <StatCard
        color="orange"
        title1="敌军人数"
        value={data?.sumary.enemy_count.toLocaleString()}
        tooltip="本场战斗中遭遇到的敌方玩家人数，点击可查看详细分布。"
        id="enemy_role"
        asLink={true}
      />
    )}

    {/* 死亡次数 */}
    {data?.sumary.death_count !== null && data?.sumary.death_count !== 0 && (
      <StatCard
        color="red"
        title1="死亡次数"
        value={data?.sumary.death_count.toLocaleString()}
        tooltip="本场战斗中你的死亡总次数，点击可查看详细分布。"
        id="death_count"
        asLink={true}
      />
    )}

    {/* 承受伤害 */}
    {data?.sumary.total_receive !== null &&
      Number(data?.sumary.total_receive ?? 0) > 0 && (
        <StatCard
          color="red"
          title1="承受伤害"
          value={parseInt(
            data?.sumary.total_receive ?? '0',
            10
          ).toLocaleString()}
          tooltip="你在本场战斗中累计承受的总伤害，点击可查看详细趋势图。"
          id="receive_damage"
          asLink={true}
        />
      )}

    {/* 输出伤害 */}
    {data?.sumary.total_damage !== null &&
      Number(data?.sumary.total_damage ?? 0) > 0 && (
        <StatCard
          color="green"
          title1="输出伤害"
          value={parseInt(
            data?.sumary.total_damage ?? '0',
            10
          ).toLocaleString()}
          tooltip="你在本场战斗中累计造成的总伤害，点击可查看详细趋势图。"
          id="output_damage"
          asLink={true}
        />
      )}

    {/* 击杀数 */}
    {data?.sumary.kill_count !== null && data?.sumary.kill_count !== 0 && (
      <StatCard
        color="green"
        title1="击杀数"
        value={data?.sumary.kill_count.toLocaleString()}
        tooltip="你在本场战斗中击杀的敌方玩家总数。"
      />
    )}

    {/* 享受洗礼 */}
    {data?.buffer_data &&
      data?.buffer_data.filter((v) => v.action === 'Receive').length > 0 && (
        <StatCard
          color="sky"
          title1="享受洗礼"
          value={data?.buffer_data
            .filter((v) => v.action === 'Receive')
            .length.toLocaleString()}
          tooltip="你在本场战斗中享受的“洗礼”类增益效果次数，点击可查看详细数据。"
          id="buffer_data"
          asLink={true}
          className="text-sky-600 hover:text-sky-800 hover:underline"
        />
      )}
  </div>
)

export default SummaryStats
